﻿#region Using Directives
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Data;
using System.Linq;
using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Entities.Validation;
using BesAsm.MasterData.Data;
using BesAsm.MasterData.Services;
#endregion

namespace BesAsm.MasterData.Services
{		
	/// <summary>
	/// An component type implementation of the 'STREET_TARGETS' table.
	/// </summary>
	/// <remarks>
	/// All custom implementations should be done here.
	/// </remarks>
	[CLSCompliant(true)]
  public partial class StreetTargetService : StreetTargetServiceBase, IArcEntityService<StreetTarget>
	{
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the StreetTargetService class.
		/// </summary>
		public StreetTargetService() : base()
		{
		}
		#endregion Constructors

    #region IArcEntityService<T> Members

    /// <summary>
    /// Gets an IArcEntity from the default service provider using the ArcGIS Object ID
    /// </summary>
    /// <param name="objectId">The Object ID of the entity to return</param>
    /// <returns>The IArcEntity with a matching Object ID</returns>
    public IArcEntity Get(int objectId)
    {
      return (IArcEntity)base.GetByObjectid(objectId);
    }

    /// <summary>
    /// Gets a TList of Link objects that match the provided ObjectId array
    /// </summary>
    /// <param name="oids">The ObjectId array to retrieve</param>
    /// <returns>A TList of Link objects</returns>
    public TList<StreetTarget> GetByOids(IEnumerable<int> oids)
    {
      List<int> oidList = oids.ToList();

      TList<Link> returnList = new TList<Link>();

      DataTable dt = new DataTable("id_table");
      dt.Columns.Add(new DataColumn("oid", typeof(Int32)));

      foreach (int oid in oids)
        dt.Rows.Add(oid);

      return this.SelectByOids(dt);
    }

    /// <summary>
    /// Gets the name of the ObjectId field.
    /// </summary>
    public string OidField { get { return "ObjectId"; } }

    #endregion

    public  IEnumerable<int> GetOidsByNodeIds(IEnumerable<int> nodeIds)
    {
      List<int> nodeIdList = nodeIds.ToList();

      TList<StreetTarget> returnList = new TList<StreetTarget>();

      DataTable dt = new DataTable("id_table");
      dt.Columns.Add(new DataColumn("id", typeof(Int32)));

      foreach (int nodeId in nodeIdList)
        dt.Rows.Add(nodeId);

      DataSet ds = this.SelectOidsByNodeIds(dt);
      dt = ds.Tables[0];

      DataRow[] dr = dt.Select();
      List<int> list = new List<int>();
      foreach (DataRow row in dr)
      {
        list.Add((int)row[0]);
      }

      return list;
    }
		
	}//End Class

} // end namespace
